<?php
//create short varible names
$username = $_POST['username'];
$num = $_POST['num'];
$price = $_POST['price'];
$address = $_POST['address'];
$zhekou = 10;
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

//判断传递过来的是不是为数字
if(!is_numeric($num)):
    echo '数量必须为数字';
    die;
endif;

//传递过来的数数字必须大于0
if($num == 0):
    echo '数字必须大于0';
    die;
endif;

if(!is_numeric($price)){
    echo '价格必须为数字';
    die;
}

if($price <= 0):
    echo '价格不能小于0';
    die;
endif;

$totalmoney = $num * $price;

$outString = '产品名称为'."\t".$username."\t".'订购数量为'.$num."\t".'订购价格为'.$price."\t".'送往'.$address."\t"."总价格为".$totalmoney."\n";
echo $outString;
//$put = file_put_contents('order.txt',$outString,FILE_APPEND);
echo "orders.txt";
//默认是追加的
@ $put = fopen("orders.txt","ab");
fwrite($put,$outString,strlen($outString));
fclose($put);
if($put){
    echo '订单添加成功';
}else {
    echo '订单添加成功';
}





